#pragma once

namespace ArkCommon
{
	namespace Math
	{
		template<class T> struct TRect;

		typedef TRect<int>		CIRect;
		typedef TRect<float>	CFRect;
		typedef TRect<CPos>		CPosRect;

		template <typename T>
		struct TRect
		{
			// Constructors
		public:
			// uninitialized rectangle
			TRect() : left( T() ),top( T() ),right( T() ),bottom( T() ){};

			// from left, top, right, and bottom
			TRect(T l, T t, T r, T b)
			{
				left		= l;
				top			= t;
				right		= r;
				bottom		= b;
			};
			// copy constructor
			TRect(const TRect<T>& srcRect)
			{
				left		= srcRect.left;
				top			= srcRect.top;
				right		= srcRect.right;
				bottom		= srcRect.bottom;
			};

			TRect(const RECT& srcRect)
			{
				left		= (T)srcRect.left;
				top			= (T)srcRect.top;
				right		= (T)srcRect.right;
				bottom		= (T)srcRect.bottom;
			};

			operator RECT() const
			{
				RECT rc = { (long)left, (long)top, (long)right, (long)bottom };
				return rc;
			}

			TRect operator& ( const TRect& rt ) const
			{
				TRect o( max( left, rt.left ), max( top, rt.top ), min( right, rt.right ), min( bottom, rt.bottom ) );
				o.bottom = max( o.top, o.bottom );
				o.right  = max( o.left, o.right );
				return o;
			}

			TRect operator+ ( const TPos<T> pos )
			{
				return TRect( left + pos.x, top + pos.y, right + pos.x, bottom + pos.y );
			}

			// Attributes (in addition to RECT members)

			// retrieves the width
			T Width() const 	{ return right - left; }
			// returns the height
			T Height() const 	{ return bottom - top; }

			T    left;
			T    top;
			T    right;
			T    bottom; 
		};

		template <>
		struct TRect<CPos>
		{
			// Constructors
		public:
			// uninitialized rectangle
			TRect() : ptLT( CPos() ), ptRT( CPos() ), ptLB( CPos() ), ptRB( CPos() ){};

			// from left, top, right, and bottom
			TRect(CPos lt, CPos rt, CPos lb, CPos rb)
			{
				ptLT		= lt;
				ptRT    	= rt;
				ptLB		= lb;
				ptRB		= rb;
			};
			// copy constructor
			TRect(const TRect<CPos>& srcRect)
			{
				ptLT		= srcRect.ptLT;
				ptRT	    = srcRect.ptRT;
				ptLB		= srcRect.ptLB;
				ptRB		= srcRect.ptRB;
			};

			/*ArkRECT(const RECT& srcRect)
			{
			ptLT		= srcRect.left;
			top			= srcRect.top;
			right		= srcRect.right;
			bottom		= srcRect.bottom;
			};

			operator RECT()
			{
			RECT rc = { left, top, right, bottom };
			return rc;
			}
			// Attributes (in addition to RECT members)

			// retrieves the width
			T Width() const 	{ return ptRB.x - ptLB; }
			// returns the height
			T Height() const 	{ return bottom - top; }*/

			CPos    ptLT;
			CPos    ptRT;
			CPos    ptLB;
			CPos    ptRB; 
		};

	};

};

using namespace ArkCommon::Math;